import 'package:bitcoin_mine/model/withdraw_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/wallet_controller.dart';

class WithdrawalList extends StatelessWidget {
  const WithdrawalList({super.key});

  @override
  Widget build(BuildContext context) {
    final WalletController controller = Get.find();

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            const Color(0xFF0084FF).withOpacity(0.0),
            const Color(0xFF0084FF),
          ],
        ),
        borderRadius: BorderRadius.circular(12.r),
        border: Border.all(color: const Color(0xFF05FFFD), width: 1),
      ),
      child: Obx(() {
        final records = controller.currentTabRecords;

        if (records.isEmpty) {
          return Container(
            padding: EdgeInsets.all(20.w),
            child: Center(
              child: Text(
                'No records found',
                style: TextStyle(color: Colors.white70, fontSize: 14.sp),
              ),
            ),
          );
        }

        return Column(
          children:
              records.asMap().entries.map((entry) {
                final index = entry.key;
                final record = entry.value;
                final isLast = index == records.length - 1;

                return _buildWithdrawalItem(record, isLast);
              }).toList(),
        );
      }),
    );
  }

  Widget _buildWithdrawalItem(WithdrawInfo record, bool isLast) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
      decoration: BoxDecoration(
        border:
            isLast
                ? null
                : Border(
                  bottom: BorderSide(
                    color: const Color(0xFF00FFFF).withOpacity(0.2),
                    width: 1,
                  ),
                ),
      ),
      child: Row(
        children: [
          // 图标
          Image.asset(
            'assets/images/icon_withdraw_record.png',
            width: 24.w,
            height: 24.h,
          ),

          SizedBox(width: 12.w),

          // 状态和日期
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  record.status == 1 ? 'Withdrawing' : 'Paid',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                Text(
                  record.created_at,
                  style: TextStyle(
                    color: Colors.white70,
                    fontSize: 12.sp,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ],
            ),
          ),

          // 金额
          Text(
            '${record.coin} btc',
            style: TextStyle(
              color: Colors.white,
              fontSize: 16.sp,
              fontWeight: FontWeight.w600,
            ),
          ),
        ],
      ),
    );
  }
}
